//非标直融
import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'manNonStandardMaintenanceM',
  state: {},
  effects: {
    // 获取列表
    *getDataList({ payload, callback }, { call, put }) {
      const response = yield call(api.manNonStandardMaintenance.nonStandardMaintenance, payload);
      if (response && response?.code == 0) {
        callback('success', response.data);
      } else {
        callback('fail');
        message.error(response?.msg || '获取列表失败！');
      }
    },
    // 批量确认
    *batchConfirm({ payload, callback }, { call, put }) {
      const response = yield call(api.manNonStandardMaintenance.nonStandardMaintenanceConfirm, payload);
      if (response && response?.code == 0) {
        callback('success');
        message.success(response?.msg || '批量确认成功');
      } else {
        callback('fail');
        message.error(response?.msg || '批量确认失败');
      }
    },
    // 回填信息
    *backfillDetail({ payload, callback }, { call, put }) {
      const response = yield call(api.manNonStandardMaintenance.nonStandardMaintenanceDetail, payload);
      if (response && response?.code == 0) {
        callback('success', response.data?.dataSource || {});
      } else {
        callback('fail');
      }
    },
    // 新增/编辑
    *nonStandardMaintenanceAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.manNonStandardMaintenance.nonStandardMaintenanceAdd, payload);
      if (response && response?.code == 0) {
        callback('success', response.data);
        message.success('操作成功');
      } else {
        callback('fail');
        message.error(response?.msg || '操作失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
